package com.lm.activiti.boot.tools.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import static org.quartz.SimpleScheduleBuilder.simpleSchedule;


/**
 * @author lm_jcf
 * @date 2020/3/20 14:46
 */
public class SchedulerDemo {

    public static void main(String[] args) throws SchedulerException {

        SchedulerFactory schedulerFactory = new StdSchedulerFactory();

        Scheduler scheduler = schedulerFactory.getScheduler();

        scheduler.start();

        JobDataMap dataMap = new JobDataMap();
        dataMap.put("name", "job");
        dataMap.put("food", "broccoli");

        JobDetail jobDetail = JobBuilder.newJob(JobDemo.class)
                .withIdentity("JobDemo", "JOB")
                .setJobData(dataMap)
                .build();

        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("triggerDemo", "TRIGGER")
                .startNow()
                .withSchedule(simpleSchedule()
                        .withIntervalInSeconds(40)
                        .repeatForever())
                .build();

        scheduler.scheduleJob(jobDetail, trigger);

    }
}
